<template>
  <div class="pay-main">
    <div class="pay-container">
      <div class="checkout-tit">
        <h4 class="tit-txt">
          <span class="success-icon"></span>
          <span class="success-info"
            >订单提交成功，请您点击图标选择支付方式，以便尽快为您发货~~</span
          >
        </h4>
      </div>

      <div class="checkout-steps">
        <div class="line"></div>
        <h5 class="t1">支付平台</h5>
        <div class="step-cont">
          <ul class="payType">
            <li @click="dialogFormVisible1 = true">
              <img src="./images/pay2.jpg" />
            </li>
            <li @click="dialogFormVisible1 = true">
              <img src="./images/pay3.jpg" />
            </li>
          </ul>
        </div>
        <div class="line"></div>

        <div class="payshipInfo">
          <div class="step-tit">
            <h5 class="t1">支付网银</h5>
          </div>
          <div class="step-cont">
            <ul class="payType" @click="dialogFormVisible2 = true">
              <li><img src="./images/pay10.jpg" /></li>
              <li><img src="./images/pay11.jpg" /></li>
              <li><img src="./images/pay12.jpg" /></li>
              <li><img src="./images/pay13.jpg" /></li>
              <li><img src="./images/pay14.jpg" /></li>
              <li><img src="./images/pay15.jpg" /></li>
              <li><img src="./images/pay16.jpg" /></li>
              <li><img src="./images/pay17.jpg" /></li>
              <li><img src="./images/pay18.jpg" /></li>
              <li><img src="./images/pay19.jpg" /></li>
              <li><img src="./images/pay20.jpg" /></li>
              <li><img src="./images/pay21.jpg" /></li>
              <li><img src="./images/pay22.jpg" /></li>
            </ul>
          </div>
        </div>
        <div class="hr"></div>

        <div class="submit">
          <a class="btn" @click="dialogFormVisible3 = true">查看订单详情</a>
        </div>
      </div>
    </div>
    <!-- 扫码支付-->
    <el-dialog
      title="扫码支付"
      :visible.sync="dialogFormVisible1"
      width="400px"
    >
      <img :src="codeUrl" alt="图片加载中" style="margin-left: 100px" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible1 = false">取 消</el-button>
        <el-button type="primary" @click="tiaozhuan">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="银行卡号支付" :visible.sync="dialogFormVisible2">
      <el-form :model="form" :rules="rules" ref="form">
        <el-form-item label="银行卡号" :label-width="formLabelWidth" prop="card">
          <el-input v-model="form.card" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible2 = false">取 消</el-button>
        <el-button type="primary" @click="tiaozhuan2">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="所有商品" :visible.sync="dialogFormVisible3">
      <el-table style="width: 100%; margin-top: 50px" border :data="extendOrdersList">
        <el-table-column
          type="index"
          label="序号"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="prop"
          label="商品名"
        ><template slot-scope="{ row }">
            {{row.orders.wares.waresName}}</template
        ></el-table-column>
        <el-table-column
          prop="prop"
          label="商品详情"
        ><template slot-scope="{ row }">
            {{row.orders.wares.waresDetail}}</template
        ></el-table-column>
        <el-table-column
          prop="prop"
          label="商品图片"
          width="200px"
          align="center"
        >
          <template slot-scope="{ row }">
            <div class="block">
              <el-carousel
                height="70px"
                :autoplay="false"
                indicator-position="none"
              >
                <el-carousel-item v-for="item in row.orders.wares.pictureList" :key="item">
                  <img :src="item" alt="123" width="70px" height="70px" />
                </el-carousel-item>
              </el-carousel>
            </div> </template
        ></el-table-column>
        <el-table-column
          prop="prop"
          label="商品数"
          width="100px"
          align="center"
        ><template slot-scope="{ row }">
            {{row.orders.waresNumber}}</template
        ></el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible3 = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import QRCode from "qrcode";
import { mapState } from "vuex";
export default {
  name: "Pay",
  data() {
    return {
      ordersId:this.$route.params.ordersId,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      dialogFormVisible3: false,
      formLabelWidth: "120px",
      codeUrl: "",
      form:{
        card:''
      },
      card: "",
      rules: {
        card: [
          { required: true, message: "请输入内容", trigger: "blur" },
          { pattern: /^\d{4}\s{1}\d{4}\s{1}\d{4}\s{1}\d{4}\s{1}$/, message: "请输入正确的银行卡密码", trigger: "blur" },
        ],
      },
    };
  },
  computed: {
    changed() {
    return this.form.card
  },
  ...mapState({
      extendOrdersList: (state) => state.shopcart.extendOrdersList,
    }),
  },
  mounted() {
    this.getPayInfo();
    this.getCodeUrl();
  },
  methods: {
    async tiaozhuan() {
      try {
        await this.$store.dispatch("changeExtendOrdersState", this.ordersId);
      } catch (error) {
        alert(error.message);
      }
      this.$router.push({ path: "/center" });
    },
    tiaozhuan2(){
      this.$refs['form'].validate((valid) => {
          if (valid) {
            this.tiaozhuan();
          } else {
            alert('请输入正确的银行卡')
          }
        });
    },
    //获取支付信息
    async getPayInfo() {
      try {
        await this.$store.dispatch("extendOrdersList", this.ordersId);
      } catch (error) {
        alert(error.message);
      }
    },
    //获取二维码
    async getCodeUrl() {
      try {
        this.codeUrl = await QRCode.toDataURL("weixin://wxpay/bizpayurl?pr=ZuHaocUzz");
      } catch (error) {
        alert(error.message);
      }
    },
  },
  watch: {
    changed: {
      handler(value, oldValue) {
        if ((value.length + 1) % 5 == 0&&value.length>oldValue.length) {
          this.form.card += " ";
        }
        if (value.length > 20) {
          this.form.card = oldValue;
        }
      },
    },
  },
};
</script>

<style lang="less" scoped>
.t1 {
  line-height: 36px;
  margin: 18px 0;
}
.pay {
  float: left;
  margin-left: 5px;
  width: 150px;
  height: 35px;
  line-height: 25px;
  text-align: center;
  border: 1px solid #ddd;
}

.pay::after {
  content: "";
  display: none;
  width: 13px;
  height: 13px;
  position: absolute;
  right: 0;
  bottom: 0;
}

.pay.selected {
  border-color: #e1251b;
}

.pay.selected::after {
  display: block;
}
.payshipInfo {
  margin-top: 50px;
}
.line {
  height: 1px;
  background-color: #ddd;
}
.pay-main {
  margin-bottom: 20px;

  .pay-container {
    margin: 0 auto;
    width: 1200px;

    a:hover {
      color: #4cb9fc;
    }

    .orange {
      color: #e1251b;
    }

    .money {
      font-size: 18px;
    }

    .zfb {
      color: #e1251b;
      font-weight: 700;
    }

    .checkout-tit {
      padding: 10px;

      .tit-txt {
        font-size: 14px;
        line-height: 21px;

        .success-icon {
          width: 30px;
          height: 30px;
          display: inline-block;
          background: url(./images/icon.png) no-repeat 0 0;
        }

        .success-info {
          padding: 0 8px;
          line-height: 30px;
          vertical-align: top;
        }
      }

      .paymark {
        overflow: hidden;
        line-height: 26px;
        text-indent: 38px;

        .fl {
          float: left;
        }

        .fr {
          float: right;

          .lead {
            margin-bottom: 18px;
            font-size: 15px;
            font-weight: 400;
            line-height: 22.5px;
          }
        }
      }
    }

    .checkout-info {
      padding-left: 25px;
      padding-bottom: 15px;
      margin-bottom: 10px;
      border: 2px solid #e1251b;

      h4 {
        margin: 9px 0;
        font-size: 14px;
        line-height: 21px;
        color: #e1251b;
      }

      ol {
        padding-left: 25px;
        list-style-type: decimal;
        line-height: 24px;
        font-size: 14px;
      }

      ul {
        padding-left: 25px;
        list-style-type: disc;
        line-height: 24px;
        font-size: 14px;
      }
    }

    .checkout-steps {
      border: 1px solid #ddd;
      padding: 25px;

      .hr {
        height: 1px;
        background-color: #ddd;
      }

      .step-tit {
        line-height: 36px;
        margin: 15px 0;
      }

      .step-cont {
        margin: 0 10px 12px 20px;

        ul {
          font-size: 0;

          li {
            margin: 2px;
            display: inline-block;
            padding: 5px 20px;
            border: 1px solid #ddd;
            cursor: pointer;
            line-height: 18px;
          }
        }
      }
    }

    .submit {
      text-align: center;

      .btn {
        display: inline-block;
        padding: 15px 45px;
        margin: 15px 0 10px;
        font: 18px "微软雅黑";
        font-weight: 700;
        border-radius: 0;
        background-color: #e1251b;
        border: 1px solid #e1251b;
        color: #fff;
        text-align: center;
        vertical-align: middle;
        cursor: pointer;
        user-select: none;
        text-decoration: none;
      }
    }
  }
}
</style>